﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Menu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["orderitems"] != null)
        {
            Total temp = new Total();
            temp = (Total) Session["mytotal"]; //total cost so far
            Master.OrderLabel = (string)Session["orderitems"]; //purchased items
            Master.TotalLabel = "Total: " + String.Format("{0:C}", temp.CurrentTotal);
        }
    }

    
    protected void PizzaGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        string myorder= "";
        decimal amt;
        Total thetotal = new Total();
        OrderItemsMain prodList = new OrderItemsMain();


        if (Session["orderitems"] != null)
        {
            thetotal = (Total)Session["mytotal"];
            myorder = (string)Session["orderitems"];
            prodList = (OrderItemsMain)Session["products"];
            myorder += "<br />";
        }
        else
        {

            Master.OrderLabel = "Order: <br />";
            myorder += Master.OrderLabel;
        }

        myorder += PizzaGridView.Rows[PizzaGridView.SelectedIndex].Cells[1].Text.ToString();
        prodList.addOrderItem(PizzaGridView.Rows[PizzaGridView.SelectedIndex].Cells[1].Text.ToString());

        amt = Convert.ToDecimal(PizzaGridView.Rows[PizzaGridView.SelectedIndex].Cells[2].Text.ToString());
        thetotal.incrTotal(amt);

        myorder += " " + String.Format("{0:C}", amt);

        Session["orderitems"] = myorder;
        Session["mytotal"] = thetotal;
        Session["products"] = prodList;

        Master.OrderLabel = myorder;
        Master.TotalLabel = "Total: " + String.Format("{0:C}", thetotal.CurrentTotal);


        
    }

    protected void SidesAndDrinksGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        string myorder = "";
        decimal amt;
        Total thetotal = new Total();
        OrderItemsMain myitems = new OrderItemsMain();

        if (Session["orderitems"] != null)
        {
            thetotal = (Total)Session["mytotal"];
            myorder = (string)Session["orderitems"];
            myitems = (OrderItemsMain)Session["products"];
            myorder += "<br />";
        }
        else
        {
            Master.OrderLabel = "Order: <br />";
            myorder += Master.OrderLabel;
        }

        myorder += SidesAndDrinksGridView.Rows[SidesAndDrinksGridView.SelectedIndex].Cells[1].Text.ToString();
        myitems.addOrderItem(SidesAndDrinksGridView.Rows[SidesAndDrinksGridView.SelectedIndex].Cells[1].Text.ToString());

        amt = Convert.ToDecimal(SidesAndDrinksGridView.Rows[SidesAndDrinksGridView.SelectedIndex].Cells[2].Text.ToString());
        thetotal.incrTotal(amt);

        myorder += " " + String.Format("{0:C}", amt);

        Session["orderitems"] = myorder;
        Session["mytotal"] = thetotal;
        Session["products"] = myitems;

        Master.OrderLabel = myorder;
        Master.TotalLabel = "Total: " + String.Format("{0:C}", thetotal.CurrentTotal);
    }
    protected void CompleteOrderButton_Click(object sender, EventArgs e)
    {
        if (Session["orderitems"] != null)
            Response.Redirect("CompletePurchase.aspx");

        else Master.OrderLabel = "Cart Empty!";
    }
}